var app = getApp();
Component({

    properties: {
        mark: Array,
        oid : Number,
    },
    data: {
        ismark : false,
        images : [],
    },
    options : {
        addGlobalClass : true,
    },
    methods: {
        showmark(){
            this.setData({
                ismark : !this.data.ismark
            })
        },
        markc(e){
            this.setData({
                content : e.detail.value
            })
        },
        showimages : function(e){
            app.com.showimages( e );
        },
        submark(e){
            var self = this;
            var postdata = {
                op : 'submark',
                oid : self.data.oid,
                content : self.data.content,
                images : JSON.stringify(self.data.images),
            };
            if(!postdata.content){
                app.com.toast('还没有填写内容');
                return false;
            }

            app.com.http('admin','POST',postdata,0,true,'','',function(res){
                if (res.data && !res.data.errno) {
                    app.com.toast(res.data.message);

                    self.data.mark.push(res.data.data);
                    self.setData({
                        content : '',
                        images : [],
                        ismark : false,
                        mark : self.data.mark,
                    })
                }else{
                    app.com.toast( res.data.message );
                }
            });
        },
        afterRead(e){
            var self = this;
            wx.showLoading({mask:true,title:'上传中'});
            wx.uploadFile({
                url: app.siteInfo.siteroot+'?i='+app.siteInfo.uniacid+'&j=&c=utility&a=file&do=upload&type=image&thumb=0',
                filePath: e.detail.file.path,
                name: 'file',
                success: function(res){
                    var aaa = JSON.parse( res.data );

                    self.data.images.push({
                        img : aaa.attachment,
                        showimg : aaa.url,
                    })
                    self.setData({
                        images : self.data.images,
                    })
                },
                complete : function(){
                    wx.hideLoading();
                },
                fail : function(rr){
                    console.log(rr)
                }
            })
        },
        delimg(e){
            var i = e.currentTarget.dataset.i;
            this.data.images.splice(i,1);
            this.setData({
                images : this.data.images
            })
        },

    }

})